@model DeathReportManagement.Models.DeathReport
@{
    ViewData["Title"] = "死亡报告详情";
}

<div class="d-flex justify-content-between align-items-center mb-3">
    <h2>死亡报告详情</h2>
    <div>
        @if (User.IsInRole("Admin") || (User.IsInRole("Doctor") && Model.AuditStatus == DeathReportManagement.Models.AuditStatus.Pending))
        {
            <a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-outline-primary">编辑</a>
        }
        <a asp-action="Index" class="btn btn-secondary">返回列表</a>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <!-- 基础信息 -->
        <div class="form-section">
            <h5>基础信息</h5>
            <div class="row">
                <div class="col-md-4">
                    <label class="form-label">报告编号</label>
                    <p class="form-control-plaintext">@Model.ReportNo</p>
                </div>
                <div class="col-md-4">
                    <label class="form-label">门诊号</label>
                    <p class="form-control-plaintext">@(Model.OutpatientNo ?? "-")</p>
                </div>
                <div class="col-md-4">
                    <label class="form-label">住院号</label>
                    <p class="form-control-plaintext">@(Model.InpatientNo ?? "-")</p>
                </div>
            </div>
        </div>
        
        <!-- 死者信息 -->
        <div class="form-section">
            <h5>死者信息</h5>
            <div class="row">
                <div class="col-md-4">
                    <label class="form-label">姓名</label>
                    <p class="form-control-plaintext">@Model.DeceasedName</p>
                </div>
                <div class="col-md-4">
                    <label class="form-label">性别</label>
                    <p class="form-control-plaintext">@Model.Gender</p>
                </div>
                <div class="col-md-4">
                    <label class="form-label">年龄</label>
                    <p class="form-control-plaintext">@Model.Age @Model.AgeUnit</p>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <label class="form-label">民族</label>
                    <p class="form-control-plaintext">@Model.Ethnicity</p>
                </div>
                <div class="col-md-4">
                    <label class="form-label">证件类型</label>
                    <p class="form-control-plaintext">@Model.IdType</p>
                </div>
                <div class="col-md-4">
                    <label class="form-label">证件号码</label>
                    <p class="form-control-plaintext">@Model.IdNumber</p>
                </div>
            </div>
        </div>
        
        <!-- 死亡信息 -->
        <div class="form-section">
            <h5>死亡信息</h5>
            <div class="row">
                <div class="col-md-6">
                    <label class="form-label">死亡时间</label>
                    <p class="form-control-plaintext">@Model.DeathDateTime.ToString("yyyy-MM-dd HH:mm")</p>
                </div>
                <div class="col-md-6">
                    <label class="form-label">死亡地点</label>
                    <p class="form-control-plaintext">@Model.DeathLocation</p>
                </div>
            </div>
        </div>
        
        <!-- 联系人信息 -->
        <div class="form-section">
            <h5>联系人信息</h5>
            <div class="row">
                <div class="col-md-6">
                    <label class="form-label">联系人姓名</label>
                    <p class="form-control-plaintext">@Model.ContactName</p>
                </div>
                <div class="col-md-6">
                    <label class="form-label">联系电话</label>
                    <p class="form-control-plaintext">@Model.ContactPhone</p>
                </div>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <!-- 状态信息 -->
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">状态信息</h6>
            </div>
            <div class="card-body">
                <div class="mb-3">
                    <label class="form-label">审核状态</label>
                    <p class="form-control-plaintext">
                        @if (Model.AuditStatus == DeathReportManagement.Models.AuditStatus.Pending)
                        {
                            <span class="badge bg-warning">待审核</span>
                        }
                        else
                        {
                            <span class="badge bg-success">已审核</span>
                        }
                    </p>
                </div>
                
                <div class="mb-3">
                    <label class="form-label">上报状态</label>
                    <p class="form-control-plaintext">
                        @switch (Model.ReportStatus)
                        {
                            case DeathReportManagement.Models.ReportStatus.NotReported:
                                <span class="badge bg-secondary">附联未上报</span>
                                break;
                            case DeathReportManagement.Models.ReportStatus.SubReported:
                                <span class="badge bg-info">附联已上报</span>
                                break;
                            case DeathReportManagement.Models.ReportStatus.MainReported:
                                <span class="badge bg-primary">主联已上报</span>
                                break;
                        }
                    </p>
                </div>
                
                <div class="mb-3">
                    <label class="form-label">创建人</label>
                    <p class="form-control-plaintext">@Model.Creator.Name</p>
                </div>
                
                <div class="mb-3">
                    <label class="form-label">创建时间</label>
                    <p class="form-control-plaintext">@Model.CreateTime.ToString("yyyy-MM-dd HH:mm")</p>
                </div>
                
                @if (Model.AuditTime.HasValue)
                {
                    <div class="mb-3">
                        <label class="form-label">审核时间</label>
                        <p class="form-control-plaintext">@Model.AuditTime.Value.ToString("yyyy-MM-dd HH:mm")</p>
                    </div>
                }
            </div>
        </div>
        
        <!-- 操作按钮 -->
        <div class="card mt-3">
            <div class="card-header">
                <h6 class="mb-0">操作</h6>
            </div>
            <div class="card-body">
                @if (User.IsInRole("Admin"))
                {
                    @if (Model.AuditStatus == DeathReportManagement.Models.AuditStatus.Pending)
                    {
                        <form asp-action="Audit" method="post" class="d-inline">
                            <input type="hidden" name="id" value="@Model.Id" />
                            <input type="hidden" name="approved" value="true" />
                            <button type="submit" class="btn btn-success btn-sm" onclick="return confirm('确认审核通过？')">审核通过</button>
                        </form>
                    }
                    
                    @if (Model.ReportStatus == DeathReportManagement.Models.ReportStatus.NotReported)
                    {
                        <form asp-action="SubReport" method="post" class="d-inline">
                            <input type="hidden" name="id" value="@Model.Id" />
                            <button type="submit" class="btn btn-info btn-sm" onclick="return confirm('确认附联上报？')">附联上报</button>
                        </form>
                    }
                    
                    @if (Model.ReportStatus == DeathReportManagement.Models.ReportStatus.SubReported)
                    {
                        <form asp-action="MainReport" method="post" class="d-inline">
                            <input type="hidden" name="id" value="@Model.Id" />
                            <button type="submit" class="btn btn-primary btn-sm" onclick="return confirm('确认主联上报？')">主联上报</button>
                        </form>
                    }
                }
                else if (User.IsInRole("Doctor"))
                {
                    @if (Model.ReportStatus == DeathReportManagement.Models.ReportStatus.NotReported)
                    {
                        <form asp-action="SubReport" method="post" class="d-inline">
                            <input type="hidden" name="id" value="@Model.Id" />
                            <button type="submit" class="btn btn-info btn-sm" onclick="return confirm('确认附联上报？')">附联上报</button>
                        </form>
                    }
                }
                
                <a asp-action="Print" asp-route-id="@Model.Id" class="btn btn-outline-secondary btn-sm" target="_blank">打印报告</a>
            </div>
        </div>
    </div>
</div>